package com.qf.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.entity.GoodsType;
import com.qf.service.IGoodTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/goodsType")
public class GoodsTypeController {

    @Autowired
    private IGoodTypeService goodTypeService;

    @GetMapping("/getGoodsTypeList")
    public List<GoodsType> getGoodsTypeList() {
        return goodTypeService.list();
    }

    @PostMapping("/addGoodsType")
    public Boolean addGoodsType(@RequestBody GoodsType goodsType) {
        return goodTypeService.save(goodsType);
    }

    @PostMapping("/updateGoodsType")
    public Boolean updateGoodsType(@RequestBody GoodsType goodsType) {
        return goodTypeService.updateById(goodsType);
    }

    @GetMapping("/deleteGoodsTypeById/{id}")
    public Boolean deleteGoodsTypeById(@PathVariable Integer id){
        return goodTypeService.removeById(id);
    }

    @GetMapping("/getGoodsTypeListByPid/{id}")
    public List<GoodsType> getGoodsTypeListByPid(@PathVariable Integer id){
        QueryWrapper<GoodsType> wrapper = new QueryWrapper<>();
        wrapper.eq("goods_type_pid",id);
        return goodTypeService.list(wrapper);
    }
}
